using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Stock.Dto;
using JTZY.Model.Stock;
using JTZY.Service.Stock.IStockService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2024-11-10
namespace JTZY.Admin.WebApi.Controllers.Stock
{
    /// <summary>
    /// 库存明细
    /// </summary>
    [Verify]
    [Route("stock/ProdStock")]
    public class ProdStockController : BaseController
    {
        /// <summary>
        /// 库存明细接口
        /// </summary>
        private readonly IProdStockService _ProdStockService;

        public ProdStockController(IProdStockService ProdStockService)
        {
            _ProdStockService = ProdStockService;
        }

        /// <summary>
        /// 查询库存明细列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "prodstock:list")]
        public IActionResult QueryProdStock([FromQuery] ProdStockQueryDto parm)
        {
            parm.UserId = HttpContext.GetUId();
            var response = _ProdStockService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询库存明细详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "prodstock:query")]
        public IActionResult GetProdStock(long Id)
        {
            var response = _ProdStockService.GetInfo(Id);
            
            var info = response.Adapt<ProdStockDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 导出库存明细
        /// </summary>
        /// <returns></returns>
        [Log(Title = "库存明细", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
        [HttpGet("export")]
        [ActionPermissionFilter(Permission = "prodstock:export")]
        public IActionResult Export([FromQuery] ProdStockQueryDto parm)
        {
            parm.PageNum = 1;
            parm.PageSize = 100000;
            var list = _ProdStockService.ExportList(parm).Result;
            if (list == null || list.Count <= 0)
            {
                return ToResponse(ResultCode.FAIL, "没有要导出的数据");
            }
            var result = ExportExcelMini(list, "库存明细", "库存明细");
            return ExportExcel(result.Item2, result.Item1);
        }

    }
}